#ifndef ENGINE_KINETIC_ANIMATION_H
#define ENGINE_KINETIC_ANIMATION_H


#include "SDL.h"

namespace Engine {

namespace Kinetic {

class Animation {
  public:
	Animation(Uint16 totalFrames, Uint16 fps = 24); 
	~Animation(); 
	inline Uint16 update(Uint16 delta); 
	inline Animation & setFPS(Uint16 amount); 
	inline Animation & setWrap(bool wrap = true); 
	inline Uint16 readFrame(); 
	Animation & setFrame(Uint16 frame); 
	inline Animation & setReverse(bool isReverse); 

  private:
	Uint16 frame; 
	Uint16 fps; 
	double totalTime; 
	double actualTime; 
	bool wrap; 
	Uint16 totalFrames; 
	bool reverse; // Animation in reverse mode? (backwards)
};
inline Uint16 Animation::update(Uint16 delta) {
	if (reverse) actualTime -= delta;
	else actualTime += delta;
	if (actualTime < 0) {
		if (wrap) actualTime = totalTime;
		else actualTime = 0;
	}
	if (actualTime > totalTime) {
		if (wrap) actualTime = 0;
		else actualTime = totalTime;
	}
	frame = (actualTime/totalTime)*(totalFrames-1);
	return frame;
}

inline Animation & Animation::setFPS(Uint16 amount) {
	fps = amount;
	totalTime = 1000.0/fps * totalFrames;
	return *this;
}

inline Animation & Animation::setWrap(bool wrap) {
	this->wrap = wrap;
	return *this;
}

inline Uint16 Animation::readFrame() {
	return frame;
}

inline Animation & Animation::setReverse(bool isReverse) {
	reverse = isReverse;
	return *this;
}


} // namespace Engine::Kinetic

} // namespace Engine
#endif
